package com.example.javaservice.controller;


import com.example.javaservice.common.Result;
import com.example.javaservice.service.CommentService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import  com.example.javaservice.pojo.Comment;

import java.util.List;

@RestController
@RequestMapping("/api/comments")
public class CommentController {

    @Resource
    private CommentService commentService;

    /** 新增评论 */
    @PostMapping
    public Result<?> addComment(@RequestBody Comment comment) {
        commentService.addComment(comment);
        return Result.success("评论成功");
    }

    /** 获取某篇文章的评论 */
    @GetMapping("/{postId}")
    public Result<List<Comment>> getComments(@PathVariable Integer postId) {
        List<Comment> list = commentService.getCommentsByPostId(postId);
        return Result.success(list);
    }
}
